/**********************************************************************************
***
***    Screencasting Teaching System C++ Library
***    Copyright (C) 2011  Jiri Novak <jiri.novak@petriny.net>
***                        Wadi Jalil Maluf <wadijm@gmail.com>
***
***    This file is part of the Screencasting Teaching System C++ Library.
***
***    This library is free software; you can redistribute it and/or modify
***    it under the terms of the GNU General Public License as published by
***   the Free Software Foundation; either version 3 of the License, or
***    (at your option) any later version.
***
***    This library is distributed in the hope that it will be useful,
***    but WITHOUT ANY WARRANTY; without even the implied warranty of
***    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
***   GNU General Public License for more details.
***
***    You should have received a copy of the GNU General Public License
***    along with this library; if not, write to the Free Software
***    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
***
*********************************************************************************/

#include <gtest/gtest.h>
#include <string>
#include "../src/common/xmlutil.h"
#include "../src/common/model/chatmessage.h"
#include "../src/common/model/user.h"
#include "../src/common/model/lesson.h"
#include "../src/common/model/course.h"

#define XML_HEADER "<?xml version=\"1.0\"?>\n"
#define XML_FOOTER "\n"

/**
 *
 */
class XmlUtilTest: public ::testing::Test {
protected:
	virtual void SetUp() {}
	virtual void TearDown() {}

	XmlUtil xmlUtil_;
};



/**
 *
 */
TEST_F(XmlUtilTest, parseAndSerializeUserWithoutCoursesAndLessonsCorrespondsTest) {
	std::string xmlUser =
		XML_HEADER
		"<user id=\"1\" instructor=\"false\" name=\"Wadi\" username=\"wadi\" password=\"wadi\"/>"
		XML_FOOTER;

	User *user = xmlUtil_.parseUser(xmlUser);

	EXPECT_EQ(xmlUser, xmlUtil_.serializeUser(*user));

	delete user;
}

/**
 *
 */
TEST_F(XmlUtilTest, parseAndSerializeLessonCorrespondsTest) {
	std::string xmlLesson =
		XML_HEADER
		"<lesson id=\"1\" name=\"Leccion I\" desc=\"descripcion\" date=\"34123123\" key=\"123\" code=\"asd\"/>"
		XML_FOOTER;

	Lesson *lesson = xmlUtil_.parseLesson(xmlLesson);

	EXPECT_EQ(xmlLesson, xmlUtil_.serializeLesson(*lesson));

	delete lesson;
}

/**
 *
 */
TEST_F(XmlUtilTest, parseAndSerializeCourseCorrespondsTest) {
	std::string xmlCourse =
		XML_HEADER
	    "<course id=\"1\" name=\"Taller I\" desc=\"descripcion\" startDate=\"1234556234\" endDate=\"231234434\" key=\"taller1\" code=\"taller1\">"
		  "<instructors>"
			"<user id=\"2\"/>"
		  "</instructors>"
		  "<students>"
			"<user id=\"1\"/>"
		  "</students>"
	      "<lessons>"
	        "<lesson id=\"1\" name=\"Leccion I Taller I\" desc=\"descripcion\" date=\"34123123\"/>"
	        "<lesson id=\"2\" name=\"Leccion II Taller I\" desc=\"descripcion\" date=\"34123123\"/>"
	        "<lesson id=\"3\" name=\"Leccion III Taller I\" desc=\"descripcion\" date=\"34123123\" key=\"taller1-extra\" code=\"taller1-extra\">"
			  "<instructors>"
				"<user id=\"2\"/>"
		  	  "</instructors>"
		  	  "<students>"
				"<user id=\"1\"/>"
	  	  	  "</students>"
			"</lesson>"
	      "</lessons>"
	    "</course>"
		XML_FOOTER;

	Course *course = xmlUtil_.parseCourse(xmlCourse);

	EXPECT_EQ(xmlCourse, xmlUtil_.serializeCourse(*course));

	delete course;
}
